from datakit_framework import DataKitFramework
import random

class HelloPythond(DataKitFramework):
    __name = 'HelloPythond'
    interval = 10 # 每 10 秒钟采集上报一次。这个根据实际业务进行调节, 这里仅作演示。

    # if your datakit ip is 127.0.0.1 and port is 9529, you won't need use this,
    # just comment it.
    # def __init__(self, **kwargs):
    #     super().__init__(ip = '127.0.0.1', port = 9529)

    def run(self):
        rd = random.randint(1, 100) # 生成一个 1 到 100 之间的随机数

        data = [
          {
              "measurement": "random_number", # 指标名称。
              "tags": {
                "tag_name": "tag_value", # 自定义 tag, 根据自己想要标记的填写, 我这里是随便写的
              },
              "fields": {
                "number": rd, # 指标, 这里是随机数
              },
          },
        ]

        in_data = {
            'M':data,
            'input': "pyfromgit"
        }

        return self.report(in_data) # you must call self.report here